#include <bits/stdc++.h>
using namespace std;

const int MC = 100005;
const int M = 10007;

int main() {
    int n, m;
    cin >> n >> m;

    vector<long long> number(n + 1);
    vector<int> color(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> number[i];
    }

    for (int i = 1; i <= n; i++) {
        cin >> color[i];
    }

    vector<vector<long long>> sum_i_num(MC, vector<long long>(2, 0));
    vector<vector<long long>> sum_i(MC, vector<long long>(2, 0));
    vector<vector<long long>> sum_num(MC, vector<long long>(2, 0));
    vector<vector<long long>> count(MC, vector<long long>(2, 0));

    long long ans = 0;

    for (int i = 1; i <= n; i++) {
        int c = color[i];
        int t = i % 2;

        ans = (ans + sum_i_num[c][t]) % M;
        ans = (ans + sum_i[c][t] * number[i]) % M;
        ans = (ans + sum_num[c][t] * (long long)i) % M;
        ans = (ans + count[c][t] * i % M * number[i] % M) % M;

        sum_i_num[c][t] = (sum_i_num[c][t] + (long long)i * number[i]) % M;
        sum_i[c][t] = (sum_i[c][t] + i) % M;
        sum_num[c][t] = (sum_num[c][t] + number[i]) % M;
        count[c][t]++;
    }

    cout << ans << endl;
    return 0;
}
